package com.lianyu507.api;

import com.lianyu507.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianyu507.service.RegisterValidateService;
	 
@Controller
public class RegisterController {
	 
	@Autowired
	private RegisterValidateService registerValidateService;

	/*
	 * 绑定邮箱
	 */
	@RequestMapping("bindEmail")
	@ResponseBody
	public String bindEmail(String token, Model model) {

		try {
			registerValidateService.bindEmail(token);
			model.addAttribute("success", true);
             return "11";
		} catch (Exception e) {
			// TODO: handle exception
			model.addAttribute("success", false);
			model.addAttribute("msg", e.getMessage());
			return "checkmail_result";
		}

	}

	/*
	 * 使用邮箱进行验证
	 */
	@RequestMapping("sendEmail")
	@ResponseBody
	public JSONResult bindPhone(String email,String password,String username) {
		JSONResult result = new JSONResult();
		try {
			registerValidateService.sendVerifyEmail(email, password, username);

		} catch (Exception e) {
			// TODO: handle exception
			result.setSuccess(false);
			result.setMsg(e.getMessage());
		}
		return result;
	}

	  
}
